package com.ymatou.iapi.sellerproduct.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerproduct.service.CancelRecommendCall;
import com.ymatou.iapi.sellerproduct.service.SetRecommendCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.mongo.LiveProductInfoWapper;
import com.ymttest.database.mongo.LiveProductModelWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.LiveProductsWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsInLiveWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*商品取消置顶
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CancelRecommend{
	private static CancelRecommendCall cancelrecommendCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品取消置顶");
	}

	@Before
	public void caseUp() {
		cancelrecommendCall=new CancelRecommendCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cancelrecommendCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_001() {
		Logger.start(true,"商品取消置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId, sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale(sellerId, sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);

			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			
			//置顶商品
			SetRecommendCall.setrecommendcall(calldate);
			
//			YMTDateUtil.waitTime(1);
			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "置顶商品，校验oldmango中应该为ture");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "置顶商品，校验newmango中应该为ture");	

			}
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
			
			//取消置顶
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate);
			
			//断言
			CancelRecommendCall.cancelrecommendGetreturncode(result);
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(0, istopstatus, "校验是否置顶状态");			
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(0, coutistop, "校验置顶商品数量");
			
			YMTDateUtil.waitTime(3);

			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(false, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
								
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_002() {
		Logger.start(true,"取消置顶再次置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing(sellerId, sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale(sellerId, sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);

			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);			
			//置顶商品
			SetRecommendCall.setrecommendcall(calldate);			
			//取消置顶
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate);
			CancelRecommendCall.cancelrecommendGetreturncode(result);
			//再次置顶商品
			JSONObject result2 = SetRecommendCall.setrecommendcall(calldate);
			SetRecommendCall.setrecommendGetreturncode(result2);
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(1, istopstatus, "校验是否置顶状态");			
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(1, coutistop, "校验置顶商品数量");
			//Mango


			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
								
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CancelRecommend_003() {
		Logger.start(true,"待销售商品取消置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个即将开始的直播
			int activityId =createLiveInFuture(sellerId, sellerName);
			//发布一个立即上架商品
			String productID = addNewProductOnSale(sellerId, sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			JSONObject dataStr = CancelRecommendCall.cancelrecommendcall(calldate);			
			//断言
			CancelRecommendCall.cancelrecommendGetreturncode(dataStr);;
			
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(0, istopstatus, "校验SQL中是否置顶状态");
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(0, coutistop, "校验置顶商品数量");


			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(false, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CancelRecommend_004() {
		Logger.start(true,"暂停销售商品取消置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing(sellerId, sellerName);
			//发布一个立即上架商品
			String productID = addNewProductOnSale(sellerId, sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			//直播中暂停销售
			SellerProductCallService.suspendSaleProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			JSONObject dataStr = SetRecommendCall.setrecommendcall(calldate);
			SetRecommendCall.setrecommendGetreturncode(dataStr);
			
			//取消置顶
			JSONObject dataStr2 = CancelRecommendCall.cancelrecommendcall(calldate);			
			//断言
			CancelRecommendCall.cancelrecommendGetreturncode(dataStr2);
			
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(0, istopstatus, "校验SQL中是否置顶状态");
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(0, coutistop, "校验置顶商品数量");


			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(false, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_005() {
		Logger.start(true,"取消置顶再次取消置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			Logger.debug(sellerId);
			//创建一个正在进行的直播
			int activityId =createLiveing(sellerId, sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale(sellerId, sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);

			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);			
			//置顶商品
			SetRecommendCall.setrecommendcall(calldate);			
			//取消置顶
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate);
			CancelRecommendCall.cancelrecommendGetreturncode(result);
			//再次取消置顶商品
			JSONObject result2 = CancelRecommendCall.cancelrecommendcall(calldate);
			CancelRecommendCall.cancelrecommendGetreturnerrcode(result2,201, 2012106, "此商品已经是未推荐商品");			
			
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();			
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(0, coutistop, "校验置顶商品数量");
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_006() {
		Logger.start(true,"置顶商品售罄后取消置顶");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId, sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale(sellerId, sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);

			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			
			//置顶商品
			SetRecommendCall.setrecommendcall(calldate);
				
			//更新库存为售罄
			updatestocknum(0 , productID);
			
			//取消置顶
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate);
			
			//断言
			CancelRecommendCall.cancelrecommendGetreturncode(result);

			YMTDateUtil.waitTime(2);
			
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(0, istopstatus, "校验是否置顶状态");			
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(0, coutistop, "校验置顶商品数量");


			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(false, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
			
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
								
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_007() {
		Logger.start(false,"非法的用户Id");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			SetRecommendCall.setrecommendcall(calldate);
				
			//取消置顶
			HashMap calldate2 = new HashMap();
			calldate2.put("UserId", 0);
			calldate2.put("ActivityId", activityId);
			calldate2.put("ProductId", productID);
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate2);			
			CancelRecommendCall.cancelrecommendGetreturnerrcode(result,400 , 0 ,"非法的用户Id");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_008() {
		Logger.start(false,"非法的直播Id");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			SetRecommendCall.setrecommendcall(calldate);
				
			//取消置顶
			HashMap calldate2 = new HashMap();
			calldate2.put("UserId", sellerId);
			calldate2.put("ActivityId", 0);
			calldate2.put("ProductId", productID);
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate2);			
			CancelRecommendCall.cancelrecommendGetreturnerrcode(result,400 , 0 ,"非法的直播Id");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_009() {
		Logger.start(false,"商品Id不能为空");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale( sellerId,  sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);
			
			//置顶商品
			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			SetRecommendCall.setrecommendcall(calldate);
				
			//取消置顶
			HashMap calldate2 = new HashMap();
			calldate2.put("UserId", sellerId);
			calldate2.put("ActivityId", activityId);
			calldate2.put("ProductId", "");
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate2);			
			CancelRecommendCall.cancelrecommendGetreturnerrcode(result,400 , 0 ,"商品Id不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_010() {
		Logger.start(false,"商品不存在");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId,  sellerName);			
				
			//取消置顶
			HashMap calldate2 = new HashMap();
			calldate2.put("UserId", sellerId);
			calldate2.put("ActivityId", activityId);
			calldate2.put("ProductId", "2314125125");
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate2);			
			CancelRecommendCall.cancelrecommendGetreturnerrcode(result,201 , 2012102 ,"商品不存在");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelRecommend_011() {
		Logger.start(true,"置顶来源为app");
		try {
			//TODO 补全case代码
			Map user = getUser();
			int sellerId = (Integer) user.get("sellerId");
			String sellerName = (String) user.get("sellerName") ;
			
			//创建一个正在进行的直播
			int activityId =createLiveing( sellerId, sellerName);			
			//发布一个立即上架商品
			String productID = addNewProductOnSale(sellerId, sellerName);
			//将商品添加到直播
			SellerProductCallService.addProductInLive(sellerId, activityId, productID);

			HashMap calldate = new HashMap();
			calldate.put("UserId", sellerId);
			calldate.put("ActivityId", activityId);
			calldate.put("ProductId", productID);
			calldate.put("OperationSource", 1);
			
			//置顶商品
			SetRecommendCall.setrecommendcall(calldate);
			
			Thread.sleep(2000);
			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(true, istopByMango, "置顶商品，校验oldmango中应该为ture");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("IsTop"), "置顶商品，校验newmango中应该为ture");	
			}
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(true, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
			
			//取消置顶
			JSONObject result = CancelRecommendCall.cancelrecommendcall(calldate);
			
			//断言
			CancelRecommendCall.cancelrecommendGetreturncode(result);
			Thread.sleep(2000);
			
			//SQL
			YmtProductsInLiveWapper pInLive = new YmtProductsInLiveWapper();	
			List<Map> pInLivelist = pInLive.selectInLiveByProductId(productID);
			int istopstatus = (int) pInLivelist.get(0).get("iIsTop");
			Logger.verifyEquals(0, istopstatus, "校验是否置顶状态");			
			List<Map> coutistoplist = pInLive.selectInLiveforcoutIstop(activityId);
			int coutistop = (int) coutistoplist.get(0).get("iIsTop");
			Logger.verifyEquals(0, coutistop, "校验置顶商品数量");


			if (YmtMongoDriverFactroy.isOldMongoCheck()){	
				//OldMango
				LiveProductInfoWapper liveProductlist  = new LiveProductInfoWapper();
				Map<String, Object> istopmap = liveProductlist.getliveproductByProductId(productID);	
				boolean istopByMango = (boolean) istopmap.get("IsTop");
				Logger.verifyEquals(false, istopByMango, "校验oldmango中是否置顶状态");				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){	
				//NewMongo
				Map<String, Object> istopmap = new LiveProductModelWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("IsTop"), "校验newmango中是否置顶状态");	
			}
					
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){	
				Map<String, Object> istopmap = new LiveProductsWapper().getByProductId(productID);
				Logger.verifyEquals(false, (boolean) istopmap.get("istop"), "校验ava newmango中是否置顶状态");	
			}	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	

	
	/**
	 * 定义发布商品的sellerid sellername
	 * @return
	 */
	private static Map getUser() {
		HashMap user = new HashMap();
		user.put("sellerId", Integer.valueOf(EnvSetup.getData("productsellerid")));
		user.put("sellerName", EnvSetup.getData("productsellername"));
		user.put("sellerId_Child", Integer.valueOf(EnvSetup.getData("productselleridChild")));
		user.put("sellerName_Child", EnvSetup.getData("productsellernameChild"));
		return user;		
	}	
	
	/**
	 * 创建一个正在执行的直播
	 * @return 直播id
	 * @throws Exception
	 */
	public static int createLiveing(int sellerId,String sellerName) throws Exception {
	    try {	    	;
			//发布商品
			JSONObject createLiveInProgressObject = LiveCallService.createLiveInProgress(sellerName,sellerId);
			Logger.verifyEquals(createLiveInProgressObject.getInt("Code"), 200, "响应报文-返回码");
			//获取返回报文的ProductID值
			int activityId =  createLiveInProgressObject.getJSONObject("Data").getInt("ActivityId");
			Logger.verifyNotNull(activityId, "响应报文-直播ID");
			return activityId;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return (Integer) null;
	}
	
	/**
	 * 创建一个即将开始的直播
	 * @return 直播id
	 * @throws Exception
	 */
	public static int createLiveInFuture(int sellerId,String sellerName) throws Exception {
	    try {	    	
			//发布商品
			JSONObject createLiveInProgressObject = LiveCallService.createLiveBeginInFuture(sellerName,sellerId);
			Logger.verifyEquals(createLiveInProgressObject.getInt("Code"), 200, "响应报文-返回码");
			//获取返回报文的ProductID值
			int activityId =  createLiveInProgressObject.getJSONObject("Data").getInt("ActivityId");
			Logger.verifyNotNull(activityId, "响应报文-直播ID");
			return activityId;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return (Integer) null;
	}
	
		
	/**
	 * 发布一个立即上架商品
	 * @return 商品id
	 * @throws Exception
	 */
	public static String addNewProductOnSale(int sellerId,String sellerName) throws Exception {
	    try {	    	
			//发布商品
			JSONObject addNewProductOnSaleObject = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null);
			Logger.verifyEquals(addNewProductOnSaleObject.getInt("Code"), 200, "响应报文-返回码");
			//获取返回报文的ProductID值
			String productID =  addNewProductOnSaleObject.getJSONObject("Data").getString("ProductID");
			Logger.verifyNotNull(productID, "响应报文-商品ID");
			return productID;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return null;
	}
	
//	/**
//	 * CALL SetRecommend
//	 * @param param 请求参数
//	 * @return 返回报文
//	 * @throws Exception
//	 */
//	public static String  cancelrecommendcall(int sellerId , int activityId , String productID) throws Exception {
//	    try {	    	
//	    	//调用接口json文件
//			Map<String,Object> calldate = new HashMap<String, Object>();
//			calldate.put("UserId", sellerId);
//			calldate.put("ActivityId", activityId);
//			calldate.put("ProductId", productID);
//			JSONObject cancelrecommendBean =  JsonBeanHelper.getJsonBean(JsonBeanFile.SetRecommendTpl);
//			cancelrecommendBean = JsonBeanHelper.updateJsonBean(cancelrecommendBean, calldate);				
//			cancelrecommendCall.setData(cancelrecommendBean);
//			cancelrecommendCall.callService();
//			String result = cancelrecommendCall.getReturnData();
//			return result;
//	    }catch (Exception e) {  
//	        e.printStackTrace();	        
//	    }  
//	    return null;
//	}
//	
//	/**
//	 * setrecommend接口返回信息公用错误信息部分断言（正向Case场景）
//	 * @throws Exception
//	 */	
//	public static void cancelrecommendGetreturncode() throws Exception {
//	    try {	    	
//			//获取返回报文的数据
//			String dataStr = cancelrecommendCall.getReturnData();
//			//返回报文断言		
//			String code =  new JSONObject(dataStr).getString("Code");
//			Logger.verifyIsContains(200, code, "\"Code\":200");
//			String msg =  new JSONObject(dataStr).getString("Msg");
//			Logger.verifyIsNull(msg, "Msg等于空");			
//			String Success =  new JSONObject(dataStr).getJSONObject("Data").getString("Success");
//			Logger.verifyIsContains(true, Success, "\"Success\":true");
//			String trace =  new JSONObject(dataStr).getString("Trace");
//			Logger.verifyIsNull(trace, "Trace等于空");
//	    	    	    	
//	    }catch (Exception e) {  
//	        e.printStackTrace();
//	    }  
//	}
	
	/**
	 * 更新库存
	 * @param iNum 库存数量
	 * @param productID 商品id
	 * @return
	 * @throws Exception
	 */
	public static String updatestocknum(int iNum ,String productID) throws Exception {
	    try {	    	
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			int ret = ymtCatalogsIWapper.updatestocknumByProductID(iNum , productID);
//			return result;
	    }catch (Exception e) {  
	        e.printStackTrace();	        
	    }  
	    return null;
	}
	
}